package samplebasic

import sweet.mvc.api._
import java.util.Date

//==> config
class SampleBasicSweetConfig extends SweetConfig {
  addSysProps("mysweetbasicdemo.config", "classpath:/config.properties")
  addProps(resourceAsStream(props("mysweetbasicdemo.config")))

  addLayouts(
    "main"->"/view/layout/main.ftl",
    "admin"->"/view/layout/admin.ftl"
  )

  addControllers(
    "/main" -> new MainController,
    "/admin" -> new AdminController(props),
    "/quickview" -> new HandlerNameViewController,  //for quick template testing.
    "/quickdata" -> new QuickTaskController  //for quick code/controller testing.
  )
}

//==> controllers
class MainController extends Controller {
  handle("/index"){ HandlerNameView() }
  handle("/hello"){ HandlerNameView() }
  handle("/sitemap"){ HandlerNameView() }
}

class AdminController(props: scala.collection.Map[String,String]) extends Controller {
  handle("/sysinfo"){ 
    HandlerNameView(
      "sysprops" -> System.getProperties,
      "appprops" -> props
    )
  }
}

/** Just return some bogus data for testing. */
class QuickTaskController extends Controller{
  handle("/index"){
    HandlerNameView(
      "now" -> new Date,
      "nowInMillis" -> new java.lang.Long(System.currentTimeMillis),
      "colors" -> List("Red", "Blue", "Yellow", "Green"),
      "customers" -> Map(
        "1001" -> new Customer("Smith", "John", 3000.23),
        "1002" -> new Customer("Dennis", "Kate", 1003.00),
        "1003" -> new Customer("Johnson", "Madison", 8713.11),
        "1003" -> new Customer("McKen", "Bill", 123435.00),
        "1004" -> new Customer("Lucene", "Matt", 0.0)
      )
    )
  }
  
  class Customer(val last: String, val first: String, val balance: Double)
}
